<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<img src="1.gif" id="deng" />
<input type="button" value="开灯" id="btn" onclick="kaiguan()">
<script>
    var isKai = false;
    function kaiguan() {
        if(isKai==true){
            deng.src="1.gif";
            btn.value="开灯";
            isKai=false;
        }else{
            deng.src="2.gif";
            btn.value="关灯";
            isKai=true;
        }
    }
</script>
</body>
</html>